# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： mlp
Description :
Author : 'li'
date： 2022/7/3
Change Activity:
2022/7/3:
-------------------------------------------------
"""
from torch import nn


class MLP(nn.Module):
    def __init__(self, input_dim, hidden_dim, output_dim, num_layers=1):
        super().__init__()
        self.num_layers = num_layers
        h = [hidden_dim] * (num_layers - 1)
        self.layers = nn.ModuleList(nn.Linear(n, k) for n, k in zip([input_dim] + h, h + [output_dim]))

    def forward(self, x):
        for i, layer in enumerate(self.layers):
            x = nn.functional.relu(layer(x)) if i < self.num_layers - 1 else layer(x)  # call activation last layer.
        return x
